﻿namespace EasyCMS.Core
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Microsoft.Practices.Unity;
    using Microsoft.Practices.Unity.Configuration;
    using System.Configuration;
    using Pismire;

    public class Subjects : MarshalByRefObject, EasyCMS.Common.ISubjects
    {
        #region Dal
        /// <summary>
        /// 通过依赖注入确定使用的数据源
        /// </summary>
        internal Dals.ISubject Dal
        {
            get
            {
                lock (syncDal)
                {
                    if (!m_DalList.ContainsKey(DataProviderName))
                    {
                        EasyCMS.Core.Dals.ISubject dal = EasyCMS.Common.Runtime.ObjectContainer.Resolve<EasyCMS.Core.Dals.ISubject>(DataProviderName);
                        dal.Init(DataProviderArgs);

                        m_DalList.Add(DataProviderName, dal);
                    }
                }
                return m_DalList[DataProviderName];
            }
        }
        private System.Collections.Generic.Dictionary<string, EasyCMS.Core.Dals.ISubject> m_DalList = new Dictionary<string, EasyCMS.Core.Dals.ISubject>();
        private object syncDal = new object();
        #endregion

        #region ISubjects 成员

        public string DataProviderName { get; private set; }

        public string DataProviderArgs { get; private set; }

        public void Setup(string dataProviderName, string dataProviderArgs)
        {
            this.DataProviderName = dataProviderName;
            this.DataProviderArgs = dataProviderArgs;
        }

        public EasyCMS.Common.DataComponents.Subject GetByID(int id)
        {
            return Dal.GetByID(id);
        }

        public EasyCMS.Common.DataComponents.Subject GetByCodeName(string codeName)
        {
            throw new NotImplementedException();
        }

        public List<EasyCMS.Common.DataComponents.Subject> GetList(EasyCMS.Common.Querys.Subject query)
        {
            int recordCount;
            query.ReadRecordCount = false;
            return GetList(query, out recordCount);
        }

        public List<EasyCMS.Common.DataComponents.Subject> GetList(EasyCMS.Common.Querys.Subject query, out int recordCount)
        {
            throw new NotImplementedException();
        }

        public ExcuteState Add(ref EasyCMS.Common.DataComponents.Subject subject)
        {
            throw new NotImplementedException();
        }

        public ExcuteState Update(ref EasyCMS.Common.DataComponents.Subject subject)
        {
            throw new NotImplementedException();
        }

        public ExcuteState Delete(int id)
        {
            throw new NotImplementedException();
        }

        public ExcuteState CreateSubjectTable(string partitionMark)
        {
            throw new NotImplementedException();
        }

        #endregion
    }
}
